<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.time.*,java.util.*" %>    <%-- 多个包之间使用“,”分割 --%>
<%@ page import="java.time.format.*" %>
<html>
<head>
    <title>import语句</title>
</head>
<body>
<%! // 定义一个全局的日期格式化格式
    public static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
%>
<%
    List<String> all = List.of("2006-10-10 21:21:21", "2008-08-08 20:08:08"); // 创建List集合
    for (String str : all) {    // foreach迭代
        try {
            LocalDateTime dateTime = LocalDateTime.parse(str, FORMATTER);
            ZoneId zoneId = ZoneId.systemDefault(); // 获取时区
            Instant instant = dateTime.atZone(zoneId).toInstant();
            Date date = Date.from(instant);
%>
            <h1>字符串转日期：<%=date%></h1>
<%
        } catch (Exception e) {}
    }
%>
</body>
</html>
